#include "Picture.h"

Picture::Picture(void)
{
}

Picture::~Picture(void)
{
	/*for(int i=0; i<height; ++i)
		delete colors[i];

	delete colors;*/
}

Picture::Picture(int width_, int height_, ColorClass backgroundColor_){
	width = width_;
	height = height_;
	backgroundColor = backgroundColor_;

	//Allocation du tableau 2D de couleurs
	colors = new ColorClass**[height];
	for(int i=0; i<height; ++i)
		colors[i] = new ColorClass*[width];
}


void Picture::saveToPpmFile(std::string fileName){
	std::ofstream out(fileName, std::ios::out);

	if(!out) return;

	std::string magicNumber = "P3";

	out << magicNumber << "\n";

	out << width << " " << height << "\n";

	out << "255" << "\n";

	for(int i=0; i<width; i++){
		for(int j=0; j<height; j++){
			out << colors[i][j]->toString() << " ";
		}
		out << "\n";
	}

	out.close();
}